home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / comm / bbs / RPGBBS3.lha / documentation / XPRotocol < prev    next >
Text File  |  1995-01-31  |  91KB  |  2,328 lines

  1. +----------------------------------------------------------------------+
  2. |                                                                      |
  3. |                  D I S C L A I M E R   N O T I C E                   |
  4. |                                                                      |
  5. |  This document and/or  portions of the material and  data furnished  |
  6. |  herewith,  was developed under sponsorship of the U.S. Government.  |
  7. |  Neither the U.S.  nor  the U.S.D.O.E.,  nor  the  Leland  Stanford  |
  8. |  Junior University, nor their employees,  nor their respective con-  |
  9. |  tractors, subcontractors, or their employees, makes  any warranty,  |
  10. |  express or implied, or assumes any liability or responsibility for  |
  11. |  accuracy,  completeness or  usefulness of any information, appara-  |
  12. |  tus, product or process disclosed, or represents that its use will  |
  13. |  not infringe privately-owned rights.  Mention of any product,  its  |
  14. |  manufacturer, or suppliers shall not, nor is it intended to, imply  |
  15. |  approval, disapproval, or fitness for any particular use. The U.S.  |
  16. |  and  the University at all times  retain the right to use and dis-  |
  17. |  seminate same for any purpose whatsoever.                           |
  18. |                                                                      |
  19. +----------------------------------------------------------------------+
  20.  
  21. Trademarks:
  22. Amiga is a trademark of Commodore Business Machines.
  23. A-Talk III is a trademark of Felsina Software.
  24. Manx is a trademark of Manx Software Systems.
  25. Lattice is a trademark of Lattice, Inc.
  26.  
  27.  
  28.  
  29.  
  30.         XPR: External File Transfer Protocols as Amiga Libraries.
  31.         =========================================================
  32.  
  33.                     Version 2.0 - 11 September 1989
  34.  
  35.                        (C) Copyright 1989 by
  36.  
  37.                          W.G.J. Langeveld
  38.  
  39.                  Stanford Linear Accelerator Center
  40.  
  41.  
  42.                               ABSTRACT
  43.                               ========
  44.  
  45.              This  document  describes a  standard method
  46.              of using  Amiga  shared  libraries  for  the
  47.              implementation  of  external  file  transfer
  48.              protocols  (XPR's), as  implemented  in  the
  49.              Amiga  terminal  emulators  A-Talk  III  and
  50.              VLT.  The  method  can  also be  used to im-
  51.              plement external terminal emulations (XEM's).
  52.  
  53.  
  54.  
  55. 1. Introduction.
  56. ================
  57.  
  58.         One of the most frequently asked questions of the author of a
  59. communications program is "Why don't you implement this wonderful file transfer
  60. protocol in addition to the 25 you already have?". Clearly, implementing more
  61. FTP's leads to larger code size and to increased product development time and
  62. customer support requirements, unless there is a way to have the additional
  63. protocols available as separate entities. One obvious way is to put the
  64. additional FTP's in overlays, but that only mitigates the code size problem and
  65. does not allow protocols to be used with communications programs of different
  66. vendors. Better is to open the serial device as a shared port and to have a
  67. completely separate program access it at the same time. However, this method has
  68. the disadvantage that shared use of a single serial port can lead to
  69. unpredictable results unless there is a well-established priority system
  70. enforcing which program is allowed to write to the device at which time. The
  71. advantage is that the FTP can now be developed separately and even by someone
  72. other than the author of the communications program. There are variations
  73. involving inter-process communication to add access control to the latter
  74. system, but I will not go into further detail.
  75.         The system described here is based on Amiga shared libraries. The
  76. library implements a small number of primary functions, such as "Send File(s)"
  77. and "Receive File(s)". These functions are called with a single argument, a
  78. pointer to an XPR_IO structure. This structure contains a number of things, the
  79. more obvious one being a pointer to a null terminated string indicating which
  80. files are to be sent or received and addresses of "call-back" functions inside
  81. the code of the communications program to access the serial device, which is
  82. opened typically in exclusive access. The scheme described here opens the
  83. possibility for the Amiga community to write a multitude of file transfer
  84. protocols, all rather small in size because they don't contain any overhead,
  85. that work with any communications program following the rules outlined in this
  86. document.
  87.         Possible problems with shared libraries are that they should be
  88. reentrant and that they should, if possible, not open dos.library [1]. On the
  89. other hand, these problems can easily be turned into advantages: for one,
  90. reentrancy is not hard to accomplish and in addition when there are multiple
  91. serial ports in use all of them can use the FTP with a single copy of the code.
  92. Not having to open dos.library can be accomplished by having call-back functions
  93. that provide all the DOS access needed in the original communications program.
  94. Typically these DOS functions are already linked into the original code anyway,
  95. and call-backs have to be provided for serial port access in any case.
  96.         For the sake of reentrancy across calls to the external protocol library
  97. (XPR), a field for storing a pointer to a data area is added for use by the XPR
  98. internally.
  99.  
  100.         Section 2 explains the library structure itself. Section 3 covers the
  101. XPR_IO structure and defines all the call-back functions. Section 4 describes an
  102. example library for a simple ASCII transfer without bells or whistles and will
  103. show how to code the library part of the call-backs. Section 5 shows how to set
  104. up a partial interface on the communications program side, sufficient to work
  105. with the ASCII example. Note: Sections 2 through 5 only describe the
  106. functionality of the specification that was present in the first public release.
  107. Section 6, finally, describes a number of extensions that were added later.
  108.  
  109.         Note: the examples are all for Manx C and assembler but should be easily
  110. modifyable for Lattice or any other language. Not all source files are given in
  111. this document. This archive, however, contains the example library plus all
  112. files needed to link it and interface to it, for Manx. Specifically, the
  113. routines that interface to XPR from VLT are in the "comm-program" subdirectory,
  114. and the sources to the library are in the "library" subdirectory. Also note,
  115. that both communications program and XPR implementers can only count on the
  116. the arguments passed in the registers as indicated. While it may appear from
  117. some of the code that the arguments are also available on the stack, this can
  118. not be relied on.
  119.  
  120.         I would like to thank Marco Papa of Felsina Software for his help in
  121. working out some of the details of the XPR standard, and Rick Huebner for his
  122. comments and debugging in the later stages.
  123.  
  124.         Neither this document, nor the XPR standard, nor the other files in this
  125. archive are in the public domain, but they may be freely distributed and used
  126. for any purpose bearing in mind the stipulations given in the disclaimer above,
  127. and with the proviso that in case of further distribution all files of this
  128. archive must remain together and unchanged.
  129.  
  130.  
  131. Reference:
  132. [1] Jim Mackraz says that opening dos.library inside a library is not a good
  133.     idea.
  134.  
  135.  
  136. 2. XPR libraries.
  137. =================
  138.  
  139.         Each external FTP is implemented as a separate library which lives in
  140. the libs: directory. It is mandatory that the names of XPR libraries start with
  141. the three letters "xpr" so that they are easily identified. The template for the
  142. name is xpr<protocol-name>.library, where <protocol-name> is a descriptive name
  143. of the protocol that is implemented. Obvious examples would be xprkermit.library
  144. and xprxmodem.library, but xprmykermit.library would be fine for a
  145. user-customized kermit implementation. When thinking of a name, the  implementer
  146. of an XPR library should keep in mind that communication programs will likely
  147. use the <protocol-name> part in their XPR requester.
  148.         Each XPR library in turn has four mandatory public functions. The
  149. functions are:
  150.  
  151.         XProtocolCleanup()
  152.         XProtocolSetup()
  153.         XProtocolSend()    and
  154.         XProtocolReceive()
  155.  
  156. in addition to the usual open, close expunge and reserved vectors. The library
  157. skeleton is given in Appendix A.
  158.         Two more library functions, XProtocolHostMon() and XProtocolUserMon(),
  159. are optional, see chapter 6.
  160.         Typically, a session with a terminal emulator using external protocols
  161. would consist of
  162.  
  163.         1. Selecting an external protocol (Using e.g. a file requester
  164.            showing only those files in libs: starting with "xpr").
  165.         2. Retrieving the library base XProtocolBase of the selected protocol
  166.            using OpenLibrary().
  167.         3. (Allocating and) initializing an XPR_IO structure.
  168.         4. Optionally calling XProtocolSetup() with the initialized structure.
  169.         5. Optionally Calling XProtocolSend() and/or XprotocolReceive() once or
  170.            multiple times to transfer files.
  171.         6. Optionally calling XProtocolSetup() to change parameters or to send
  172.            special commands. Perhaps repeat 5.
  173.         7. Calling XprotocolCleanup() to deallocate any resources allocated by
  174.            XProtocolSetup(). (Deallocate the XPR_IO structure if needed).
  175.         8. Closing the library using CloseLibrary().
  176.         9. Repeat the process, or
  177.        10. Exit.
  178.  
  179.         All four XPR functions take a single argument, a pointer to an XPR_IO
  180. structure, properly initialized as described in section 5, and passed in
  181. register A0. After XProtocolSetup() has been called, the same XPR_IO structure
  182. should be used for calls to any of the other functions. Only the xpr_filename
  183. field is allowed to be changed between  calls. In particular, the xpr_data field
  184. is for internal use by the XPR library only! It should be initialized to NULL
  185. before calling XProtocolSetup() and should not be changed by the communications
  186. program. XProtocolSetup() should be called once right after opening the library
  187. and subsequently only at the request of the user. XProtocolCleanup() should
  188. always be called before the library is closed.
  189.         In the form of a sample program, the rules above look like this:
  190.  
  191. /** MyWonderFullCommProgram.c
  192. *
  193. *   Just an example. An actual implementation would likely look different.
  194. *
  195. **/
  196. #include <stdio.h>
  197. #include <functions.h>
  198. #include "xproto.h"
  199.  
  200. struct Library *XProtocolBase = NULL;
  201.  
  202. #define SEND 1
  203. #define RECEIVE 2
  204. #define INITIALIZE 3
  205.  
  206. main()
  207. {
  208.    struct XPR_IO io;
  209.    int user_said, Waiting_for_user_input();
  210.  
  211.    XProtocolBase = OpenLibrary("xprascii.library", 0L);
  212.    if (XProtocolBase == NULL) {
  213.       printf("protocol not found\n");
  214.       exit(10);
  215.    }
  216.  
  217. /*
  218. *   Initialize structure (see later).
  219. */
  220.    xpr_setup(io);
  221. /*
  222. *   Retrieve the initalization string
  223. */
  224.    Get_init_string_from_user_or_wherever(buffer);
  225.    io->xpr_filename = buffer;
  226.    XProtocolSetup(io);
  227.  
  228.    while (user_said = Waiting_for_user_input(filename)) {
  229.       if (user_said == SEND) {
  230.          io->xpr_filename = filename;
  231.          XProtocolSend(io);
  232.       }
  233.       else if (user_said == RECEIVE) {
  234.          io->xpr_filename = filename;
  235.          XProtocolReceive(io);
  236.       }
  237.       else if (user_said == INITIALIZE) {
  238.          io->xpr_filename = NULL;
  239.          XProtocolSetup(io);
  240.       }
  241.    }
  242.  
  243.    XProtocolCleanup(io);
  244.  
  245.    CloseLibrary(XProtocolBase);
  246.  
  247.    exit(0);
  248. }
  249.  
  250.         Clearly, only one FTP can be active at any particular instant in the
  251. life of the session of the communications program. However, this is not really a
  252. limitation in practice, and can be worked around at the cost of some amount of
  253. programming effort.
  254.         XProtocolSetup(), XProtocolSend(), XProtocolReceive() and
  255. XProtocolCleanup() return 0L on failure, non-zero on success. Note to XPR
  256. implementers: the vanilla success return code should be 1L. Other bits in the
  257. return code may have special meaning, see section 6.
  258.  
  259.  
  260.  
  261.  
  262. 3. The XPR_IO structure.
  263. ========================
  264.  
  265.         The XPR_IO structure definition is given in Appendix B. The reader
  266. should keep in mind that the callback functions are to be implemented by the
  267. author of the communications program, not by the author of the external
  268. protocol. However, most communications programs already have functions that
  269. perform the operations listed here, so the implementation should not be too
  270. difficult. Also, the communications program author is not required, strictly
  271. speaking, to implement any of the functions: functions that are not implemented
  272. should be indicated by initializing the corresponding XPR_IO field to NULL.
  273. Obviously, a minimum set of functions must be implemented in order to be useful.
  274. On the other hand, it is up to the implementer of the external protocol to
  275. determine if the given set of functions is sufficient to perform the protocol
  276. transfer. In case of missing functions (indicated by NULL fields in the XPR_IO
  277. structure) suitable default actions should be taken.
  278.  
  279.         We will now examine all the fields of XPR_IO in detail. 
  280.  
  281.  
  282. 3.1     char  *xpr_filename;
  283. ----------------------------
  284.  
  285.         The xpr_filename field is used primarily to pass null-terminated strings
  286. containing a file name (or file names specified by wild cards) to the functions
  287. XProtocolSend() or XProtocolReceive(). The XPR implementer may elect to support
  288. wild cards in the file name. Call-backs for finding the first and next filename
  289. matching the pattern are provided in the XPR_IO structure, but on the other hand
  290. XPR implementers should take care to check that these call-backs are implemented
  291. by the communications program by testing the corresponding XPR_IO fields for
  292. NULL. Never assume that all call-backs are implemented! If a particular
  293. call-back without which the XPR cannot function is not implemented, the XPR
  294. should fail gracefully.
  295.  
  296.         The xpr_filename field can also be used to pass an initialization string
  297. to XProtocolSetup(). Typically, if this field is left NULL in a call to
  298. XProtocolSetup(), it would be the duty of XProtocolSetup() to query the user for
  299. initialization information, using e.g. the xpr_gets function (see later). If an
  300. initialization string is present, XProtocolSetup() should NOT query the user,
  301. but this is left to the discretion of the implementer of the protocol, as is the
  302. precise form of the initialization string. It is the duty of the communications
  303. program to determine any default initialization strings for the protocol in
  304. question. Suggested is the use of environment variables named for the protocols
  305. they refer to, containing the initialization string. For the simple Ascii
  306. protocol shown later, the user might have a statement like
  307.  
  308.         set xprascii=50
  309.  
  310. in his startup sequence, or with AmigaDOS 1.3, a file called xprascii in his
  311. env: directory containing the letters "50" (50 referring here to the number of
  312. ticks delay between 80-character packets - obviously more extensive
  313. initialization might be needed).
  314.         Given the presence of such default information, XProtocolSetup() should
  315. always be called using the default initialization string right after opening the
  316. library. Conversely, a mechanism (menu option) should be present in the
  317. communications program to change the settings by calling XProtocolSetup() with a
  318. NULL value for this field. On the other hand, if no default initialization
  319. string is present, the legal situation can arise that XProtocolSetup() is never
  320. called.
  321.         It should be noted that XProtocolSetup() can be used to implement any
  322. commands not directly related to sending or receiving files. Examples that come
  323. to mind are Kermit Bye and Finish. One should keep in mind, that typically the
  324. communications program does not know what protocol it is running, much less what
  325. commands that protocol might support. When the user asks to "setup" the external
  326. protocol, XProtocolSetup() should be called with a NULL xpr_filename field,
  327. and the external protocol should request a command, as stated before. In the
  328. case of an external Kermit protocol, the user might type a Bye or Finish, and
  329. the external protocol could act accordingly. See section 6 for additional
  330. information.
  331.  
  332.         The xpr_filename field is ignored by the XProtocolCleanup() function.
  333.  
  334.  
  335. 3.2    long (*xpr_fopen)();
  336. ---------------------------
  337.  
  338.         The xpr_fopen() call-back function works in most respects identically to
  339. the stdio function fopen(). Calling sequence:
  340.  
  341.         long fp = (*xpr_fopen)(char *filename, char *accessmode)
  342.         D0                     A0              A1
  343.  
  344. The result is a FILE structure, but one should not count on it being a
  345. particular one, since it may be compiler dependent. The return value should only
  346. be used in calls to other stdio functions. The only accesmodes available are
  347. "r"  (read-only)
  348. "w"  (write-only, create new file if none exists, truncate existing file)
  349. "a"  (write-only, create new file if none exists, append to existing file)
  350. "r+" (same as "r", but may also write)
  351. "w+" (same as "w", but may also read)
  352. "a+" (same as "a", but may also read).
  353.         An error return is indicated when the function returns NULL.
  354.         Note that the arguments must be passed in registers A0 and A1
  355. respectively. See also section 4.
  356.  
  357.  
  358. 3.3     long (*xpr_fclose)();
  359. -----------------------------
  360.  
  361.         The xpr_fclose() call-back function works in most respects identically
  362. to the stdio function fclose(). Calling sequence:
  363.  
  364.         (*xpr_fclose)(long filepointer)
  365.                       A0
  366.  
  367. Note that the argument must be passed in register A0.
  368.  
  369.  
  370. 3.4     long (*xpr_fread)();
  371. ----------------------------
  372.  
  373.         The xpr_fread() call-back function works in most respects identically to
  374. the stdio function fread(). Calling sequence:
  375.  
  376.         long count = (*xpr_fread)(char *buffer, long size, long count,
  377.         D0                        A0            D0         D1
  378.  
  379.                                   long fileptr)
  380.                                   A1
  381.  
  382. The function returns the actual number items read. The size argument is in bytes.
  383. The function returns 0 on error or end of file.
  384.  
  385.  
  386. 3.5     long (*xpr_fwrite)();
  387. -----------------------------
  388.  
  389.         The xpr_fwrite() call-back function works in most respects identically
  390. to the stdio function fwrite(). Calling sequence:
  391.  
  392.         long count = (*xpr_fwrite)(char *buffer, long size, long count,
  393.         D0                         A0            D0         D1
  394.  
  395.                                   long fileptr)
  396.                                   A1
  397.  
  398. The function returns the actual number items written. The size argument is in
  399. bytes. The function returns 0 on failure.
  400.  
  401.  
  402. 3.6     long (*xpr_sread)();
  403. ----------------------------
  404.  
  405.         The xpr_sread() call-back function has the following calling sequence:
  406.  
  407.         long count = (*xpr_sread)(char *buffer, long size, long timeout)
  408.         D0                        A0            D0         D1
  409.  
  410. The first argument is a pointer to a buffer to receive the characters from the
  411. serial port, with a size specified in the second argument. The third item is a
  412. timeout in microseconds. The function returns the actual number of characters
  413. put into the buffer, or -1L on error. When the timeout argument is non-zero, the
  414. function will return when one of three events occurs: (1) the timeout period
  415. has expired, or (2) the buffer has been filled with  exactly "size" characters,
  416. or (3) an error occurs.
  417.         Specifically, when the routine is called, a timer is started and set to
  418. the value contained in timeout. The routine now starts collecting data from the 
  419. serial port and stores them in buffer. If the timer times out before size
  420. characters are received, the routine returns immediately with count set to the
  421. actual number of characters received. In case no characters at all are received,
  422. it will return count = 0L. If the buffer is full before the timer has expired,
  423. the routine returns immediately with count = size. It is up to the XPR to set
  424. the  timeout long enough to ensure that at the current baud rate the buffer can
  425. actually be filled to the specified size within the timeout period. The routine
  426. can also return with count set to -1L. This might happen, for example, when the
  427. carrier is lost. The XPR should then fairly quickly get around to checking
  428. the abort status using the xpr_chkabort() function: BBS programs will want to
  429. regain control quickly after the carrier is dropped.
  430.         The timeout may be set to 0L if the objective is to just read any
  431. characters that may currently be available. In this case, the function will not
  432. start up a timer, but will instead check the serial device for currently
  433. available characters and return them in the usual fashion, and return as quickly
  434. as possible. Note: the value 0L for the timeout argument is a special case.
  435. Remember that AmigaDOS 1.3 may have problems with small non-zero values for
  436. timeouts.
  437.     Further notes on the implementation of xpr_sread() can be found in the
  438. discussion about XProtocolHostMon in section 6.3.1.
  439.  
  440.  
  441. 3.7     long (*xpr_swrite)();
  442. -----------------------------
  443.  
  444.         The xpr_swrite() call-back function has the following calling sequence:
  445.  
  446.         long status = (*xpr_swrite)(char *buffer, long size)
  447.         D0                          A0            D0
  448.  
  449. This function writes a buffer with the given size to the serial port. It returns
  450. 0L on success, non-zero on failure.
  451.  
  452. 3.8     long (*xpr_sflush)();
  453. ----------------------------
  454.  
  455.         The xpr_sflush call-back function has the following calling sequence:
  456.  
  457.         long status = (*xpr_sflush)()
  458.         D0
  459.  
  460. This function flushes all the data in the serial port input buffer.  It is
  461. typically used to recover after a protocol error. The function returns 0L on
  462. success, non-zero on failure.
  463.  
  464. 3.9     long (*xpr_update)();
  465. -----------------------------
  466.  
  467.         The xpr_update() call-back function has the following calling sequence:
  468.  
  469.         (*xpr_update)(struct XPR_UPDATE *updatestruct)
  470.                       A0
  471. where:
  472.  
  473. struct XPR_UPDATE {     long  xpru_updatemask;
  474.                         char *xpru_protocol;
  475.                         char *xpru_filename;
  476.                         long  xpru_filesize;
  477.                         char *xpru_msg;
  478.                         char *xpru_errormsg;
  479.                         long  xpru_blocks;
  480.                         long  xpru_blocksize;
  481.                         long  xpru_bytes;
  482.                         long  xpru_errors;
  483.                         long  xpru_timeouts;
  484.                         long  xpru_packettype;
  485.                         long  xpru_packetdelay;
  486.                         long  xpru_chardelay;
  487.                         char *xpru_blockcheck;
  488.                         char *xpru_expecttime;
  489.                         char *xpru_elapsedtime;
  490.                         long  xpru_datarate;
  491.                         long  xpru_reserved1;
  492.                         long  xpru_reserved2;
  493.                         long  xpru_reserved3;
  494.                         long  xpru_reserved4;
  495.                         long  xpru_reserved5;
  496.                    }
  497.  
  498. This function is intended to communicate a variety of values and strings from
  499. the external protocol to the communications program for display. Hence, the
  500. display format itself (requester, text-I/O) is left to the implementer of the
  501. communications program.
  502.         The mask xpru_updatemask indicates which of the other fields are valid,
  503. i.e. have had their value updated. It is possible to update a single or multiple
  504. values. Values that the external protocol does not use can be indicated by a
  505. NULL for pointers and -1L for longs.
  506.         The possible bit values for the xpru_updatemask are:
  507.  
  508.                 #define XPRU_PROTOCOL           0x00000001L
  509.                 #define XPRU_FILENAME           0x00000002L
  510.                 #define XPRU_FILESIZE           0x00000004L
  511.                 #define XPRU_MSG                0x00000008L
  512.                 #define XPRU_ERRORMSG           0x00000010L
  513.                 #define XPRU_BLOCKS             0x00000020L
  514.                 #define XPRU_BLOCKSIZE          0x00000040L
  515.                 #define XPRU_BYTES              0x00000080L
  516.                 #define XPRU_ERRORS             0x00000100L
  517.                 #define XPRU_TIMEOUTS           0x00000200L
  518.                 #define XPRU_PACKETTYPE         0x00000400L
  519.                 #define XPRU_PACKETDELAY        0x00000800L
  520.                 #define XPRU_CHARDELAY          0x00001000L
  521.                 #define XPRU_BLOCKCHECK         0x00002000L
  522.                 #define XPRU_EXPECTTIME         0x00004000L
  523.                 #define XPRU_ELAPSEDTIME        0x00008000L
  524.                 #define XPRU_DATARATE           0x00010000L
  525.  
  526.         The other fields of the XPR_UPDATE structure have the following
  527. meaning:
  528.  
  529. xpru_protocol    -- a string that indicates the name of the protocol used
  530. xpru_filename    -- the name of the file currently sent or received
  531. xpru_filesize    -- the size of the file
  532. xpru_msg         -- a "generic" message (50 characters or less)
  533. xpru_errormsg    -- an "error" message  (50 characters or less)
  534. xpru_blocks      -- number of transferred blocks
  535. xpru_blocksize   -- size of most recently transferred block (bytes)
  536. xpru_bytes       -- number of transferred bytes
  537. xpru_errors      -- number of errors
  538. xpru_timeouts    -- number of timeouts
  539. xpru_packettype  -- type of packet (e.g. Kermit 'D'-packet)
  540. xpru_packetdelay -- delay between packets in msec
  541. xpru_chardelay   -- delay between characters in msec
  542. xpru_blockcheck  -- block check type (e.g. "Checksum", "CRC-16", "CRC-32")
  543. xpru_expecttime  -- expected transfer time (e.g. "5 min 20 sec", "00:05:30")
  544. xpru_elapsedtime -- elapsed time from start of transfer (see xpru_expecttime)
  545. xpru_datarate    -- rate of data transfer expressed in characters per second.
  546. xpru_reserved1   -- for further expansion
  547.  ...         .   --  ...
  548. xpru_reserved5   -- for further expansion
  549.  
  550.         The communications program is free to ignore any field and to only update
  551. the ones it can handle.
  552.         If xpru_updatemask is equal to -1L, then ALL fields are either valid or 
  553. are unambiguously valued to indicate they are unused: NULL for pointers and -1L
  554. for longs.
  555.         When writing an external protocol, it is advisable to keep any strings
  556. as short as possible, and not longer than about 50 characters. Remember, if your
  557. strings are too long, they may overflow whatever display mechanism the
  558. communications program has chosen. It is also advisable to fill in as many
  559. fields as you can, since the communications program may not choose to display
  560. the ones you favor. When writing a communications program interface to XPR, on
  561. the other hand, remember that strings can be as much as 50 characters long. If
  562. you don't receive your favorite variables, it may be possible to compute them
  563. from those that are given. It is good practice for the external protocol to call
  564. xpr_update before starting the transfer with a message in the xpru_msg field
  565. indicating whether the protocol is sending or receiving a file.
  566.         The XPR_UPDATE structure must be provided by the external protocol, and
  567. must, of course be allocated either on the stack (as a local variable) or using
  568. AllocMem or malloc(). This is needed to ensure reentrancy. In general, it is a
  569. good idea to keep the entire library reentrant, since more than one
  570. communications program may be using the same code simultaneously. (If you use
  571. malloc(), make sure your implementation of malloc() is reentrant!).
  572.  
  573.  
  574. 3.10     long (*xpr_chkabort)();
  575. -------------------------------
  576.  
  577.         The xpr_chkabort() call-back function has no arguments:
  578.  
  579.         long status = (*xpr_chkabort)()
  580.         D0
  581.  
  582. When it returns non-zero, it means that the user has requested an abort. It is
  583. possible to implement levels of abort by returning 1L, 2L, 3L, etc, depending on
  584. the user's actions. The highest level of abort is -1L, which should be
  585. interpreted to mean stop all actions and return. The chkabort function should be
  586. called reasonably frequently.
  587.  
  588.  
  589. 3.11    long (*xpr_chkmisc)();
  590. ------------------------------
  591.  
  592.         The xpr_chkmisc() call-back function has no arguments and returns
  593. nothing.
  594.  
  595.         (*xpr_chkmisc)()
  596.  
  597. It is intended to give the communications program that is currently executing
  598. the external protocol transfer a chance to service its various message ports and
  599. to respond to user actions. It should be called on a regular basis.
  600.  
  601.  
  602. 3.12    long (*xpr_gets)();
  603. ---------------------------
  604.  
  605.         The xpr_gets() call-back function works somewhat like the stdio function
  606. gets(). Calling sequence:
  607.  
  608.         long status = (*xpr_gets)(char *prompt, char *buffer)
  609.         D0                        A0            A1
  610.  
  611. The first argument is a pointer to a string containing a prompt, to be displayed
  612. by the communications program in any manner it sees fit. The second argument
  613. should be a pointer to a buffer to receive the user's response. It should have a
  614. size of at least 256 bytes. The function returns 0L on failure or user
  615. cancellation, non-zero on success. The buffer has to be supplied by the XPR.
  616.  
  617.  
  618. 3.13    long (*xpr_setserial)();
  619. --------------------------------
  620.  
  621.         The xpr_setserial() call-back function has the following calling
  622. sequence:
  623.  
  624.         long oldstatus = (*xpr_setserial)(long newstatus)
  625.         D0                                D0
  626.  
  627. This function returns the current serial device status in encoded form. If the
  628. newstatus argument is -1L, the serial device status will not be changed.
  629. Otherwise the serial device status will be changed to newstatus. If oldstatus
  630. is returned as -1L, the call failed and the serial status was not changed.
  631.         Note: if the serial device status is changed with this function, the 
  632. external protocol must change the status back to oldstatus before returning.
  633.  
  634.         serial status longword:
  635.         .......................
  636.  
  637.         byte 0:         as the SerFlags field in IOExtSer structure.
  638.                 bit 0:  - parity on if set
  639.                 bit 1:  - parity odd if set
  640.                 bit 2:  - 7-wire protocol enabled if set
  641.                 bit 3:  - queued break if set
  642.                 bit 4:  - rad-boogie if set
  643.                 bit 5:  - shared if set
  644.                 bit 6:  - EOF mode if set
  645.                 bit 7:  - Xon/Xoff disabled if set
  646.         byte 1:         summary of other settings
  647.                 bit 0:  - enable mark/space parity if set
  648.                 bit 1:  - parity mark if set, space otherwise
  649.                 bit 2:  - 2 stop bits if set, 1 otherwise
  650.                 bit 3:  - read wordlength is 7 if set, 8 otherwise
  651.                 bit 4:  - write wordlength is 7 if set, 8 otherwise
  652.                 bit 5:  - not used
  653.                 bit 6:  - not used
  654.                 bit 7:  - not used
  655.         byte 2:         specifies one of a limited set of baud rates, as in
  656.                         preferences.h.
  657.                         -    110 baud =  0
  658.                         -    300 baud =  1
  659.                         -   1200 baud =  2
  660.                         -   2400 baud =  3
  661.                         -   4800 baud =  4
  662.                         -   9600 baud =  5
  663.                         -  19200 baud =  6
  664.                         -   midi      =  7
  665.                         -  38400 baud =  8
  666.                         -  57600 baud =  9
  667.                         -  76800 baud = 10
  668.                         - 115200 baud = 11
  669.         byte 3:         not used
  670.  
  671.  
  672. 3.14    long (*xpr_ffirst)();
  673. -----------------------------
  674.  
  675.         The xpr_ffirst() call-back function has the calling sequence:
  676.  
  677.         long stateinfo = (*xpr_ffirst)(char *buffer, char *pattern)
  678.         D0                             A0            A1
  679.  
  680. The first argument is a buffer to receive the first filename that matches the
  681. pattern in the second argument. The function returns 0L if no file matching the
  682. pattern was found, non-zero otherwise. The buffer should have a size of at least
  683. 256 bytes and is provided by the XPR. See also 3.14.
  684.  
  685.  
  686. 3.15    long (*xpr_fnext)();
  687. ----------------------------
  688.  
  689.         The xpr_fnext() call-back function has the calling sequence:
  690.  
  691.         long stateinfo = (*xpr_fnext)(long oldstate, char *buffer, char *pattern)
  692.         D0                            D0             A0            A1
  693.  
  694. The first argument is a buffer to receive the next filename that matches the
  695. pattern in the second argument. The function returns 0L if no further file
  696. matching the pattern was found, non-zero otherwise. The buffer should have a
  697. size of at least 256 bytes and is provided by the XPR.
  698.         Note: the value returned by xpr_ffirst and xpr_fnext may be used by the
  699. implementing communications program to maintain state information, but the
  700. mechanism is up to the implementer. If reentrancy is not required, state
  701. information may be kept in global variables by the implementer, and the oldstate
  702. argument can be ignored. However, the external protocol implementation must pass
  703. the stateinfo variable returned by ffirst or fnext to the next invocation of
  704. fnext.
  705.  
  706.  
  707. 3.16    long (*xpr_finfo)();
  708. ----------------------------
  709.  
  710.         The xpr_finfo() call-back function has the calling sequence:
  711.  
  712.         long info = (*xpr_finfo)(char *filename, long typeofinfo)
  713.         D0                       A0              D0
  714.  
  715. This function returns information about a file given its name and the type of
  716. information requested. Notice that some information may not be accessible if
  717. the file is already write locked. Therefore, you should call this function
  718. (where appropriate) before opening the file.
  719.  
  720.         typeofinfo value:       resulting info:              on failure:
  721.         ..................................................................
  722.  
  723.         1L                      file size (bytes)            0L
  724.  
  725.         2L                      file type: 1L is binary,     0L
  726.                                            2L is text.
  727.  
  728.         (other values)          (to be determined)
  729.  
  730.  
  731. 3.17    long  *xpr_fseek();
  732. ---------------------------
  733.  
  734.         The xpr_fseek() call-back function works in most respects identically to
  735. the stdio function fseek(). Calling sequence:
  736.  
  737.         long status = (*xpr_fseek)(long fileptr, long offset, long origin)
  738.         D0                         A0            D0           D1
  739.  
  740. This function sets the current position of a file to "offset" from the 
  741. beginning (origin = 0), current position (origin = 1) or end (origin = 2) of
  742. the file.
  743. The function returns 0 on success.
  744.  
  745.  
  746. 3.18    long  *xpr_extension;
  747. -----------------------------
  748.  
  749.         This field indicates how many extension fields follow this structure.
  750. Before using any of those functions or fields (as defined in section 6), the
  751. XPR must check that the desired function is indeed present by ensuring that
  752. xpr_extension is larger than the position of the function beyond the xpr_data
  753. field.
  754.  
  755.  
  756. 3.19    long  *xpr_data;
  757. ------------------------
  758.  
  759.         This field is for internal use by the external protocol. Typically the
  760. field is initialized to point to a structure containing information extracted
  761. from the initialization string handed to or retrieved by the XProtocolSetup()
  762. function, see section 2. The structure should be deallocated and the field
  763. restored to NULL by the XProtocolCleanup() function. The communications program
  764. should never access this field, except when initializing the XPR_IO structure:
  765. the field should be initialized to NULL.
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772. 4. An example protocol.
  773. =======================
  774.  
  775.         The following is an annotated listing of an ascii upload protocol.
  776. Notice that the files supplied in this archive are likely more up to date and
  777. more extensive than the example given here.
  778.  
  779. /** xprascii.c
  780. *
  781. *   These are the protocol transfer routines for a simple ASCII upload.
  782. *
  783. **/
  784. #include <exec/exec.h>
  785. #include <functions.h>
  786. #include <stdio.h>
  787. /*
  788. *   xproto.h is the include file given in Appendix B.
  789. */
  790. #include "xproto.h"
  791. /*
  792. *   The following two strings must exist.
  793. */
  794. char  XPRname[]   = "xprascii.library";
  795. char  XPRid[]     = "xprascii 0.9 (May 89)\r\n";
  796. UWORD XPRrevision = 9;
  797.  
  798. long atol();
  799. /*
  800. *   The callxx...() routines are described later. They provide the 
  801. *   assembler interface from the XPR library to the call-back routines.
  802. */
  803. long calla(), callaa(), callad(), calladd(), calladda();
  804.  
  805. char *malloc();
  806.  
  807.  
  808. /**
  809. *
  810. *   Send a file
  811. *
  812. **/
  813. long XProtocolSend(IO)
  814. struct XPR_IO *IO;
  815. {
  816.    long fp, r, i;
  817.    long brkflag = 0, fl = 0L, sd = 0L;
  818.    long (*xupdate)(), (*xswrite)(), (*xfopen)(), (*xfclose)(), (*xfread)(),
  819.         (*xsread)(),  (*xchkabort)();
  820.    unsigned char *buff = NULL, *serbuff = NULL;
  821.    struct XPR_UPDATE xpru;
  822.  
  823. /*
  824. *   These are the call-backs we need. If any of them isn't provided, quit.
  825. *   Could do some error reporting if at least xupdate is there.
  826. */
  827.    if ((xupdate    = IO->xpr_update)   == NULL) return(0L);
  828.    if ((xswrite    = IO->xpr_swrite)   == NULL) return(0L);
  829.    if ((xfopen     = IO->xpr_fopen)    == NULL) return(0L);
  830.    if ((xfclose    = IO->xpr_fclose)   == NULL) return(0L);
  831.    if ((xfread     = IO->xpr_fread)    == NULL) return(0L);
  832.    if ((xsread     = IO->xpr_sread)    == NULL) return(0L);
  833.    if ((xchkabort  = IO->xpr_chkabort) == NULL) return(0L);
  834. /*
  835. *   Allocate a few buffers.
  836. */
  837.    buff    = (unsigned char *) malloc(80);
  838.    serbuff = (unsigned char *) malloc(80);
  839. /*
  840. *   If we ran out of memory, print a message.
  841. *   The argument needs to go in A0: calla does this for us. 
  842. */
  843.    if (buff == NULL || serbuff == NULL) {
  844.       xpru.xpru_updatemask = XPRU_ERRORMSG;
  845.       xpru.xpru_errormsg   = "Ran out of memory!";
  846.       calla(xupdate, &xpru);
  847.       return(0L);
  848.    }
  849. /*
  850. *   Read the send delay, if a XProtocolSetup() was done before.
  851. *   If send delay is too large, cut it off at 10 seconds.
  852. *   In this example, the xpr_data field contains a null terminated string
  853. *   containing the number of ticks to delay each 80 characters.
  854. */
  855.    if (IO->xpr_data) {
  856.       sd = atol(IO->xpr_data);
  857.       if (sd > 500L) sd = 500L;
  858.    }
  859. /*
  860. *   Open the file. One could do wild card detection here.
  861. *   xfopen requires two arguments, in a0 and a1 respectively.
  862. *   Again, this must be done in assembler, and callaa does it.
  863. */
  864.    fp = callaa(xfopen, IO->xpr_filename, "r");
  865.    if (fp == NULL) {
  866.       free(buff);
  867.       free(serbuff);
  868.       xpru.xpru_updatemask = XPRU_ERRORMSG | XPRU_FILENAME;
  869.       xpru.xpru_errormsg   = "Failed to open input file";
  870.       xpru.xpru_filename   = IO->xpr_filename;
  871.       calla(xupdate, &xpru);
  872.       return(0L);
  873.    }
  874. /*
  875. *   Start the transfer. See 3.8 for a discussion on how to implement
  876. *   xupdate. 
  877. */
  878.    xpru.xpru_updatemask = XPRU_MSG | XPRU_FILENAME;
  879.    xpru.xpru_msg        = "Starting ASCII Send";
  880.    xpru.xpru_filename   = IO->xpr_filename;
  881.    calla(xupdate, &xpru);
  882. /*
  883. *   Now read 80 byte chunks from the file using xfread.
  884. *   xfread requires four arguments, a0, d0, d1 and a1.
  885. */
  886.    xpru.xpru_blocks = 0L;
  887.    while (r = calladda(xfread, buff, 1L, 80L, fp)) {
  888. /*
  889. *   Convert line feeds to carriage returns before sending to host.
  890. *   fl counts the characters. Display how many characters are sent.
  891. */
  892.       for (i = 0L; i < r; i++) if (buff[i] == '\n') buff[i] = '\r';
  893.       fl += r;
  894.       xpru.xpru_updatemask = XPRU_BYTES | XPRU_BLOCKS | XPRU_BLOCKSIZE;
  895.       xpru.xpru_bytes      = fl;
  896.       xpru.xpru_blocks++;
  897.       xpru.xpru_blocksize  = r;
  898.       calla(xupdate, &xpru);
  899.       callad(xswrite, buff, r);
  900. /*
  901. *   Every 80 bytes, put out a message and delay if requested.
  902. */
  903.       xpru.xpru_updatemask  = XPRU_PACKETDELAY;
  904.       xpru.xpru_packetdelay = sd * 20L;  /* msec! */
  905.       calla(xupdate, &xpru);
  906. /*
  907. *   Can't use Delay() here, because Delay() is in dos.library!
  908. *   However writing an equivalent function using the timer.device is
  909. *   trivial.
  910. */
  911.       TimeOut(sd);
  912. /*
  913. *   Eat any characters that might arrive from the serial port.
  914. *   calladd stores arg1 in a0, arg2 in d0, arg3 in d1.
  915. *   We're not really waiting for any characters: use a timeout of 0L.
  916. */
  917.       while (calladd(xsread, serbuff, 80L, 0L) > 0L) ;
  918. /*
  919. *   Check for "abort" here. Perhaps should call chkmisc() as well.
  920. */
  921.       if (brkflag = xchkabort()) break;
  922.    }
  923. /*
  924. *   Close the file
  925. */
  926.    calla(xfclose, fp);
  927.    free(buff);
  928.    free(serbuff);
  929. /*
  930. *   If we got here through chkabort() say Aborted.
  931. */
  932.    xpru.xpru_updatemask       = XPRU_MSG;
  933.    if (brkflag) xpru.xpru_msg = "Aborted";
  934.    else         xpru.xpru_msg = "Done"; 
  935.    calla(xupdate, &xpru);
  936.    if (brkflag) return(0L);
  937.    else         return(1L);
  938. }
  939.  
  940.  
  941. /**
  942. *
  943. *   Receive a file.
  944. *
  945. **/
  946. long XProtocolReceive(IO)
  947. struct XPR_IO *IO;
  948. {
  949.    long fp, r, i;
  950.    long brkflag = 0, fl = 0L, sd = 0L;
  951.    long (*xupdate)(), (*xswrite)(), (*xfopen)(), (*xfclose)(), (*xfwrite)(),
  952.         (*xsread)(),  (*xchkabort)();
  953.    unsigned char *serbuff = NULL;
  954.    struct XPR_UPDATE xpru;
  955.  
  956. /*
  957. *   These are the call-backs we need. If any of them isn't provided, quit.
  958. *   Could do some error reporting if at least xupdate is there.
  959. */
  960.    if ((xupdate    = IO->xpr_update)   == NULL) return(0L);
  961.    if ((xswrite    = IO->xpr_swrite)   == NULL) return(0L);
  962.    if ((xfopen     = IO->xpr_fopen)    == NULL) return(0L);
  963.    if ((xfclose    = IO->xpr_fclose)   == NULL) return(0L);
  964.    if ((xfwrite    = IO->xpr_fwrite)   == NULL) return(0L);
  965.    if ((xsread     = IO->xpr_sread)    == NULL) return(0L);
  966.    if ((xchkabort  = IO->xpr_chkabort) == NULL) return(0L);
  967. /*
  968. *   Allocate a buffer.
  969. */
  970.    serbuff = (unsigned char *) malloc(80);
  971. /*
  972. *   If we ran out of memory, print a message.
  973. *   The argument needs to go in A0: calla does this for us. 
  974. */
  975.    if (serbuff == NULL) {
  976.       xpru.xpru_updatemask = XPRU_ERRORMSG;
  977.       xpru.xpru_errormsg   = "Ran out of memory!";
  978.       calla(xupdate, &xpru);
  979.       return(0L);
  980.    }
  981. /*
  982. *   Open the file.
  983. *   xfopen requires two arguments, in a0 and a1 respectively.
  984. *   Again, this must be done in assembler, and callaa does it.
  985. */
  986.    fp = callaa(xfopen, IO->xpr_filename, "w");
  987.    if (fp == NULL) {
  988.       free(serbuff);
  989.       xpru.xpru_updatemask = XPRU_ERRORMSG | XPRU_FILENAME;
  990.       xpru.xpru_errormsg   = "Failed to open output file";
  991.       xpru.xpru_filename   = IO->xpr_filename;
  992.       calla(xupdate, &xpru);
  993.       return(0L);
  994.    }
  995. /*
  996. *   Start the transfer. See 3.8 for a discussion on how to implement
  997. *   xupdate. 
  998. */
  999.    xpru.xpru_updatemask = XPRU_MSG | XPRU_FILENAME;
  1000.    xpru.xpru_msg        = "Starting ASCII Receive";
  1001.    xpru.xpru_filename   = IO->xpr_filename;
  1002.    calla(xupdate, &xpru);
  1003. /*
  1004. *   Now read 80 byte chunks from the serial port using xsread. Stop
  1005. *   when no characters arrive for 5 sec.
  1006. */
  1007.    xpru.xpru_blocks = 0L;
  1008.    while ((r = calladd(xsread, serbuff, 80L, 5000000L)) > 0L)  {
  1009. /*
  1010. *   Strip high-bit before storing in file.
  1011. *   fl counts the characters. Display how many characters are received.
  1012. */
  1013.       for (i = 0L; i < r; i++) serbuff[i] &= 0177;
  1014.       fl += r;
  1015.       xpru.xpru_updatemask = XPRU_BYTES | XPRU_BLOCKS | XPRU_BLOCKSIZE;
  1016.       xpru.xpru_bytes      = fl;
  1017.       xpru.xpru_blocks++;
  1018.       xpru.xpru_blocksize  = r;
  1019.       calla(xupdate, &xpru);
  1020. /* 
  1021. *   Write 80 byte chunks to the file using xwrite
  1022. */
  1023.       calladda(xfwrite, serbuff, 1L, r, fp);
  1024.  
  1025. /*
  1026. *   Check for "abort" here. Perhaps should call chkmisc() as well.
  1027. */
  1028.       if (brkflag = xchkabort()) break;
  1029.    }
  1030. /*
  1031. *   Close the file
  1032. */
  1033.    calla(xfclose, fp);
  1034.    free(serbuff);
  1035. /*
  1036. *   If we got here through chkabort() say Aborted.
  1037. */
  1038.    xpru.xpru_updatemask       = XPRU_MSG;
  1039.    if (brkflag) xpru.xpru_msg = "Aborted";
  1040.    else         xpru.xpru_msg = "Done"; 
  1041.    calla(xupdate, &xpru);
  1042.    if (brkflag) return(0L);
  1043.    else         return(1L);
  1044. }
  1045.  
  1046.  
  1047. /**
  1048. *
  1049. *   Setup
  1050. *
  1051. **/
  1052. long XProtocolSetup(IO)
  1053. struct XPR_IO *IO;
  1054. {
  1055.    long (*xupdate)(), (*xgets)();
  1056.    struct XPR_UPDATE xpru;
  1057.  
  1058.    if ((xupdate = IO->xpr_update) == NULL) return(0L);
  1059.    if ((xgets   = IO->xpr_gets)   == NULL) return(0L);
  1060. /*
  1061. *   Allocate a bit of memory for a data buffer
  1062. */
  1063.    if (IO->xpr_data == NULL) {
  1064.       if ((IO->xpr_data = (long *) malloc(256)) == NULL) {
  1065.          xpru.xpru_updatemask = XPRU_ERRORMSG;
  1066.          xpru.xpru_errormsg   = "ASCII - Out of memory!";
  1067.          calla(xupdate, &xpru);
  1068.          return(0L);
  1069.       }
  1070.    }
  1071. /*
  1072. *   If setup string isn't handed to us, ask questions
  1073. */
  1074.    if (IO->xpr_filename == NULL) {
  1075. /*
  1076. *   Get the value for the send delay
  1077. */
  1078.       callaa(xgets, "Enter ASCII send delay (ticks, 1 tick = 20 msec)",
  1079.                   IO->xpr_data);
  1080.    }
  1081.    else {
  1082.       strcpy(IO->xpr_data, IO->xpr_filename);
  1083.    }
  1084.    
  1085.    return(1L);
  1086. }
  1087.  
  1088. /**
  1089. *
  1090. *   Cleanup
  1091. *
  1092. **/
  1093. long XProtocolCleanup(IO)
  1094. struct XPR_IO *IO;
  1095. {
  1096.    if (IO->xpr_data) free(IO->xpr_data);
  1097.    IO->xpr_data = NULL;
  1098.  
  1099.    return(1L);
  1100. }
  1101.  
  1102. /**
  1103. *
  1104. *   The following functions setup the proper registers for the call-back 
  1105. *   functions.
  1106. *
  1107. **/
  1108. #asm
  1109.         public _callad
  1110. _callad:
  1111.         movea.l 8(sp),a0                ; Second argument goes in a0
  1112.         move.l  12(sp),d0               ; Third  argument goes in d0
  1113. /*
  1114. *   Now this is a trick to avoid using another register.
  1115. *   Charlie taught me this...
  1116. */
  1117.         move.l  4(sp),-(sp)             ; First  argument is function
  1118.         rts
  1119.  
  1120.         public  _calladda
  1121. _calladda:
  1122.         movea.l 8(sp),a0                ; Second argument goes in a0
  1123.         move.l  12(sp),d0               ; Third  argument goes in d0
  1124.         move.l  16(sp),d1               ; Fourth argument goes in d1
  1125.         movea.l 20(sp),a1               ; Fifth  argument goes in a1
  1126.         move.l  4(sp),-(sp)             ; First  argument is function
  1127.         rts
  1128.  
  1129.         public  _calla
  1130. _calla:
  1131.         movea.l 8(sp),a0                ; Second argument goes in a0
  1132.         move.l  4(sp),-(sp)             ; First  argument is function
  1133.         rts
  1134.  
  1135.         public  _callaa
  1136. _callaa:
  1137.         movea.l 8(sp),a0                ; Second argument goes in a0
  1138.         movea.l 12(sp),a1               ; Third  argument goes in a1
  1139.         move.l  4(sp),-(sp)             ; First  argument is function
  1140.         rts
  1141.  
  1142.         public  _calladd
  1143. _calladd:
  1144.         move.l  8(sp),a0                ; Second argument goes in a0
  1145.         move.l  12(sp),d0               ; Third  argument goes in d0
  1146.         move.l  16(sp),d1               ; Fourth argument goes in d1
  1147.         move.l  4(sp),-(sp)             ; First  argument is function
  1148.         rts
  1149.  
  1150. #endasm
  1151. /*
  1152. *   Could have added any other functions needed for other call-backs.
  1153. *   Could have written a fancier single one... Could've...
  1154. */
  1155.                               __                
  1156.                              /  \ o    /        
  1157.                        -----/----\----/-----
  1158.                            /    o \__/          
  1159.                                                 
  1160.         Clearly it isn't very hard to implement a simple protocol. More
  1161. elaborate protocols are straightforward extensions to the above example. Of
  1162. course, there are a few more standard files needed to make the above example
  1163. into a complete library (like Open, Close and Expunge functions and a ROM-Tag
  1164. structure) but those parts are the same for any library and aren't given here.
  1165.  
  1166.  
  1167.  
  1168. 5. The interface to the communications program.
  1169. ===============================================
  1170.  
  1171.         The following is an annotated listing of a few call-back functions as
  1172. they are implemented in VLT. Also, it is shown how to initialize the XPR_IO
  1173. structure. Notice that the files supplied in this archive are likely more up to
  1174. date and more extensive than the minimal example given here.
  1175.  
  1176. /** xprfuncs.c
  1177. *
  1178. *   Call-back functions for eXternal PRotocol support
  1179. *
  1180. **/
  1181. #include <functions.h>
  1182. #include <exec/exec.h>
  1183. #include <stdio.h>
  1184. /*
  1185. *   xproto.h is given in Appendix B
  1186. */
  1187. #include "xproto.h"
  1188. /*
  1189. *   xfer.h is a VLT private header file containing some information for
  1190. *   file transfer protocols
  1191. */
  1192. #include "xfer.h"
  1193.  
  1194. /*
  1195. *   These are the C versions of the interface
  1196. */
  1197. long        vlt_update(),  vlt_swrite(),  vlt_fread(),  vlt_fopen(),
  1198.             vlt_fclose(),  vlt_gets(),    vlt_sread(),  vlt_chkabort();
  1199. /*
  1200. *   These are the assembly level glue functions, see vltface.asm
  1201. */
  1202. extern long avlt_update(), avlt_swrite(), avlt_fread(), avlt_fopen(),
  1203.             avlt_fclose(), avlt_gets(),   avlt_sread(), avlt_chkabort();
  1204.  
  1205. /**
  1206. *
  1207. *   This function initializes an XPR_IO structure.
  1208. *
  1209. **/
  1210. xpr_setup(IO)
  1211. struct XPR_IO *IO;
  1212. {
  1213. /*
  1214. *   NULL out all the functions we don't do yet.
  1215. *   Fill the other ones with the addresses to the assembler glue version
  1216. *   of the interface routines. See vltface.asm
  1217. */
  1218.    IO->xpr_filename  = NULL;
  1219.    IO->xpr_fopen     = avlt_fopen;
  1220.    IO->xpr_fclose    = avlt_fclose;
  1221.    IO->xpr_fread     = avlt_fread;
  1222.    IO->xpr_fwrite    = NULL;
  1223.    IO->xpr_sread     = avlt_sread;
  1224.    IO->xpr_swrite    = avlt_swrite;
  1225.    IO->xpr_sflush    = NULL;
  1226.    IO->xpr_update    = avlt_update;
  1227.    IO->xpr_chkabort  = avlt_chkabort;
  1228.    IO->xpr_chkmisc   = NULL;
  1229.    IO->xpr_gets      = avlt_gets;
  1230.    IO->xpr_setserial = NULL;
  1231.    IO->xpr_ffirst    = NULL;
  1232.    IO->xpr_fnext     = NULL;
  1233.    IO->xpr_finfo     = NULL;
  1234.    IO->xpr_fseek     = NULL;
  1235. /*
  1236. *   Support the 1 defined extension
  1237. */
  1238.    IO->xpr_extension = 1L;
  1239. /*
  1240. *   But don't actually implement it yet.
  1241. */
  1242.    IO->xpr_options   = NULL
  1243. /*
  1244. *   Especially, NULL out the XPR private data field.
  1245. */
  1246.    IO->xpr_data      = NULL;
  1247.  
  1248.    return;
  1249. }
  1250.  
  1251. /**
  1252. *
  1253. *   Interface to VLT's MsgDisplay() function.
  1254. *
  1255. **/
  1256. /*
  1257. *   These are formats for VLT's requester
  1258. */
  1259. static char *xprnamfmt = "%s\n%s\n\n\n\n";
  1260. static char *filnamfmt = "\n\n%s\n\n\n";
  1261. static char *blksizfmt = "\n\n\n\nBlock:  %6ld  --  Block Size:  %6ld\n";
  1262. static char *errtimfmt = "\n\n\n\n\nErrors: %6ld  --  Timeouts:    %6ld";
  1263. static char *delayfmt  = "\n\n\n\n\nPacket delay %ld";
  1264. /*
  1265. *   Below are some VLT globals to orchestrate the display
  1266. */
  1267. long xpr_blocks = 0L, xpr_blocksize = 0L, xpr_errors = 0L, xpr_timeouts = 0L;
  1268. /*
  1269. *   The function
  1270. */
  1271. long vlt_update(x)
  1272. struct XPR_UPDATE *x;
  1273. {
  1274.    extern struct Window *mywindow;
  1275.    extern char *XPR_Name;
  1276. /*
  1277. *   First time, determine the window size (50 chars wide, 5 lines tall).
  1278. */
  1279.    SetMsgWindow(mywindow, 50, 6);
  1280. /*
  1281. *   Use VLT's PostMsg function to display all the information.
  1282. */
  1283.    if (x->xpru_updatemask & XPRU_PROTOCOL) {
  1284.       PostMsg(mywindow, xprnamfmt, XPR_Name, x->xpru_protocol);
  1285.    }
  1286.    if (x->xpru_updatemask & XPRU_MSG) {
  1287.       PostMsg(mywindow, xprnamfmt, XPR_Name, x->xpru_msg);
  1288.    }
  1289.    if (x->xpru_updatemask & XPRU_ERRORMSG) {
  1290.       PostMsg(mywindow, xprnamfmt, XPR_Name, x->xpru_errormsg);
  1291.    }
  1292.    if (x->xpru_updatemask & XPRU_FILENAME) {
  1293.       PostMsg(mywindow, filnamfmt, x->xpru_filename);
  1294.    }
  1295.    if (x->xpru_updatemask & XPRU_PACKETDELAY) {
  1296.       PostMsg(mywindow, delayfmt, x->xpru_packetdelay);
  1297.    }
  1298.    if (x->xpru_updatemask & (XPRU_BLOCKS | XPRU_BLOCKSIZE)) {
  1299.       if (x->xpru_updatemask & XPRU_BLOCKS)    xpr_blocks    = x->xpru_blocks;
  1300.       if (x->xpru_updatemask & XPRU_BLOCKSIZE) xpr_blocksize = x->xpru_blocksize;
  1301.       PostMsg(mywindow, blksizfmt, xpr_blocks, xpr_blocksize);
  1302.    }
  1303.    if (x->xpru_updatemask & (XPRU_ERRORS | XPRU_TIMEOUTS)) {
  1304.       if (x->xpru_updatemask & XPRU_ERRORS)   xpr_errors   = x->xpru_errors;
  1305.       if (x->xpru_updatemask & XPRU_TIMEOUTS) xpr_timeouts = x->xpru_timeouts;
  1306.       PostMsg(mywindow, errtimfmt, xpr_errors, xpr_timeouts);
  1307.    }
  1308.    return(0L);
  1309. }
  1310.  
  1311. /**
  1312. *
  1313. *   Prompt the user for input
  1314. *
  1315. **/
  1316. long vlt_gets(s, t)
  1317. char *s, *t;
  1318. {
  1319. /*
  1320. *   Use VLT's DoRequest() function
  1321. */
  1322.    return((long) DoRequest(mywindow, t, s, NULL, " Cancel "));
  1323. }
  1324.  
  1325. /**
  1326. *
  1327. *   Write a string to the serial port
  1328. *
  1329. **/
  1330. long vlt_swrite(s, n)
  1331. char *s;
  1332. long n;
  1333. {
  1334. /*
  1335. *   Use VLT's SendString() function
  1336. */
  1337.    SendString(s, (int) n);
  1338.    return(0L);
  1339. }
  1340.  
  1341. /**
  1342. *
  1343. *   Read characters from the serial port
  1344. *
  1345. **/
  1346. long vlt_sread(buff, length, micros)
  1347. unsigned char *buff;
  1348. long length, micros;
  1349. {
  1350.    extern int timeout;
  1351.    long secs = 0L;
  1352.  
  1353.    if (buff == NULL) return(-1L);
  1354. /*
  1355. *   Convert timeout to seconds and micros if necessary
  1356. */
  1357.    if (micros) {
  1358.       if (micros > 1000000L) {
  1359.          secs   = micros / 1000000L;
  1360.          micros = micros % 1000000L;
  1361.       }
  1362.    }
  1363. /*
  1364. *   What follows is pseudo code. VLT's implementation is at this point
  1365. *   different.
  1366. */
  1367.    StartTimer(secs, micros);
  1368. /*
  1369. *   VLT has a global called timeout. This comes in xfer.h.
  1370. *   If the read was successful, add character to buffer.
  1371. */
  1372.    for (i = 0; (timeout == GOODREAD) && (i < size); i++)
  1373.       buff[i] = (unsigned char) readchar();
  1374. /*
  1375. *   Either timed out or buffer is full.
  1376. */
  1377.    if (timeout != TIMEOUT) AbortTimer();
  1378. /*
  1379. *   If carrier dropped, return error condition
  1380. */
  1381.    if (timeout == CARRIER_DROPPED) return(-1L);
  1382. /*
  1383. *   Else return the number of characters read.
  1384. */
  1385.    return(i);
  1386. }
  1387.  
  1388. /**
  1389. *
  1390. *   Interfaces to stdio
  1391. *
  1392. **/
  1393. long vlt_fopen(s, t)
  1394. char *s, *t;
  1395. {
  1396.    return((long) fopen(s, t));
  1397. }
  1398.  
  1399. long vlt_fclose(fp)
  1400. FILE *fp;
  1401. {
  1402.    return((long) fclose(fp));
  1403. }
  1404.  
  1405. long vlt_fread(buff, size, count, fp)
  1406. char *buff;
  1407. long size, count;
  1408. FILE *fp;
  1409. {
  1410.    int res;
  1411.    res = fread(buff, (int) size, (int) count, fp);
  1412.    return((long) res);
  1413. }
  1414.  
  1415. /**
  1416. *
  1417. *   Check for Abort
  1418. *
  1419. **/
  1420. long vlt_chkabort()
  1421. {
  1422. /*
  1423. *   VLT aborts its protocols when the escape key is pressed.
  1424. *   CheckForKey loops over the UserPort messages looking for an escape.
  1425. */
  1426.    return((long) CheckForKey(69));
  1427. }
  1428.                               __                
  1429.                              /  \ o    /        
  1430.                        -----/----\----/-----
  1431.                            /    o \__/          
  1432.                                                 
  1433.         Clearly, this part of the implementation isn't hard either. The only
  1434. thing left is the assembly level glue on the communications program side. You
  1435. may wonder at this point why all this assembly level stuff is necessary. It is
  1436. necessary because many programs and libraries are written in small code/small
  1437. data. This means that both the communications program and the library address
  1438. their code/data off of some register, in the case of Manx usually A4. The
  1439. problem is that the communications program and the library are loaded in
  1440. different parts of memory, while startup code takes care of setting up the
  1441. proper value for A4. And the values of A4 are different for the the
  1442. communications program and the library! Now, if you just call a library
  1443. function, the assembly level glue does a few things, among which are: (1) saving
  1444. the caller's A4 somewhere safe and (2) retrieving the A4 it stored somewhere
  1445. when the library was loaded. Then the library function is executed, and the
  1446. function returns to the glue. The glue then restores A4 to the state it was in
  1447. before the library call.
  1448.         In the case of these call-back functions, we have to do the reverse.
  1449. After all, when a function like xpr_update is called, the current value of A4 is
  1450. the one that goes with the library's code. If the call-back function tries to
  1451. access any data back in the communications program, we're in big trouble.
  1452.         So what the assembly part of the call-backs has to do is (1) save the
  1453. library's A4 (on the stack) and (2) get the value of A4 appropriate for the
  1454. communications program. Then we can push the various registers onto the stack,
  1455. call the C version of the call-back and then restore the value of A4 to what the
  1456. library wants.
  1457.         For the above call-backs, the assembly level glue is listed below. 
  1458.  
  1459. ;;; vltface.asm
  1460. ;
  1461. ;   DESCRIPTION:
  1462. ;   ===========
  1463. ;
  1464. ;        This is an interface to VLT callback functions from
  1465. ;        external protocol libraries.
  1466. ;
  1467. ;   AUTHOR/DATE:  W.G.J. Langeveld, March 1989.
  1468. ;   ============
  1469. ;
  1470. ;;;
  1471.  
  1472.         public  _geta4
  1473.  
  1474. setup   macro
  1475.         movem.l d2/d3/d4-d7/a2-a6,-(sp)
  1476.         jsr     _geta4                        ; Get a4.
  1477.         endm
  1478.  
  1479. push    macro
  1480.         move.l  \1,-(sp)
  1481.         endm
  1482.  
  1483. fix     macro
  1484.         ifc     '\1',''
  1485.                 mexit
  1486.         endc
  1487.         ifle    \1-8
  1488.                 addq.l  #\1,sp
  1489.         endc
  1490.         ifgt    \1-8
  1491.                 lea     \1(sp),sp
  1492.         endc
  1493.         endm
  1494.  
  1495. restore macro
  1496.         fix     \1
  1497.         movem.l (sp)+,d2/d3/d4-d7/a2-a6        
  1498.         rts
  1499.         endm
  1500.  
  1501.         public  _avlt_fopen
  1502.         public  _vlt_fopen
  1503.         public  _avlt_fclose
  1504.         public  _vlt_fclose
  1505.         public  _avlt_fread
  1506.         public  _vlt_fread
  1507.         public  _avlt_sread
  1508.         public  _vlt_sread
  1509.         public  _avlt_swrite
  1510.         public  _vlt_swrite
  1511.         public  _avlt_update
  1512.         public  _vlt_update
  1513.         public  _avlt_chkabort
  1514.         public  _vlt_chkabort
  1515.         public  _avlt_gets
  1516.         public  _vlt_gets
  1517.  
  1518. _avlt_fopen:
  1519.         setup
  1520.         push    a1
  1521.         push    a0
  1522.         jsr     _vlt_fopen
  1523.         restore 8
  1524.  
  1525. _avlt_fclose:
  1526.         setup
  1527.         push    a0
  1528.         jsr     _vlt_fclose
  1529.         restore 4
  1530.  
  1531. _avlt_fread:
  1532.         setup
  1533.         push    a1
  1534.         push    d1
  1535.         push    d0
  1536.         push    a0
  1537.         jsr     _vlt_fread
  1538.         restore 16
  1539.  
  1540. _avlt_sread:
  1541.         setup
  1542.         push    d1
  1543.         push    d0
  1544.         push    a0
  1545.         jsr     _vlt_sread
  1546.         restore 12
  1547.  
  1548. _avlt_swrite:
  1549.         setup
  1550.         push    d0
  1551.         push    a0
  1552.         jsr     _vlt_swrite
  1553.         restore 8
  1554.  
  1555. _avlt_update:
  1556.         setup
  1557.         push    a0
  1558.         jsr     _vlt_update
  1559.         restore 4
  1560.  
  1561. _avlt_chkabort:
  1562.         setup
  1563.         jsr     _vlt_chkabort
  1564.         restore
  1565.  
  1566. _avlt_gets:
  1567.         setup
  1568.         push    a1
  1569.         push    a0
  1570.         jsr     _vlt_gets
  1571.         restore 8
  1572.  
  1573.                               __                
  1574.                              /  \ o    /        
  1575.                        -----/----\----/-----
  1576.                            /    o \__/          
  1577.                                                 
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584. 6. XPR Extensions
  1585. =================
  1586.  
  1587.         While simple protocols can usually get by with the functionality  given
  1588. in sections 2 through 5 above, some more elaborate protocols may need additional
  1589. functionality. Also, one may want to present the user with a more polished
  1590. interface in certain situations. This is accomplished under the XPR
  1591. specification in a number of ways.
  1592.         It has become clear that in many cases the communications program needs
  1593. to know a few details about the XPR that it is currently running. Some of these
  1594. relate to simple yes/no decisions on the part of the communications program, and
  1595. can be represented as bits that are either set or not. A number of bits in the
  1596. return codes of the XProtocolSetup() function have been defined in this way, and
  1597. they are listed in section 6.1.
  1598.         The straightforward way to extend the XPR capabilities is through the
  1599. use of more call-back functions. The first such function, xpr_options(), was
  1600. already described in a previous release of this document. This document will
  1601. describe and standardize this and a few more such functions in section 6.2.
  1602.         Finally, there is a need in certain file transfer protocols to monitor
  1603. what host and/or user are doing even while not in the process of sending or
  1604. receiving files by protocol transfer. For that purpose, a few XPR library
  1605. functions have been added. The mechanics of this is described in section 6.3.
  1606.  
  1607.  
  1608. 6.1 Library function calling conventions and return codes.
  1609. ----------------------------------------------------------
  1610.  
  1611.         This section defines more precisely what the return codes of the four
  1612. standard XPR library functions mean. Also, in some cases calling conventions
  1613. are more clearly specified.
  1614.  
  1615. 6.1.1 XProtocolSetup()
  1616. ----------------------
  1617.  
  1618.         The library function XProtocolSetup() is called with as the single
  1619. argument a pointer to a previously initialized XPR_IO structure. The calling
  1620. sequence is:
  1621.  
  1622.         long setup_flags = XProtocolSetup(struct XPR_IO *IO);
  1623.         D0                                A0
  1624.  
  1625. where struct XPR_IO is defined as in section 3 and appendix B.
  1626.         When this function is called by the communications program with a NULL
  1627. value in the xpr_filename field, the function is expected to prompt the user for
  1628. setup information. When the xpr_filename field points to a null terminated
  1629. string, this string is expected to be interpreted as a direct command or
  1630. initialization sequence, and the function is in general NOT expected to prompt
  1631. the user for input. An exception to this latter rule occurs, when the command or
  1632. initialization string directly or indirectly instructs the XPR to prompt the
  1633. user for input. In particular, the empty string "", should always be interpreted
  1634. as a void command (a NOP), and should never cause XProtocolSetup() to prompt for
  1635. input.
  1636.         This is particularly useful when the communications program only wants
  1637. to retrieve the value of setup_flags, which is the return code of
  1638. XProtocolSetup(), without going through the protocol setup sequence.
  1639.         With this extension of the specification, it now becomes natural to 
  1640. always call XProtocolSetup() right after opening the XPR library, either with an
  1641. empty string or with an initialization string if one can be found. In all cases,
  1642. the XPR should return a proper value for the return code, as defined below. The
  1643. communications program still should have a menu option or other way to allow the
  1644. user to go through an XPR setup sequence, by calling XProtocolSetup() with a
  1645. NULL pointer in the xpr_filename field.
  1646.  
  1647.         The return code, setup_flags, is a bit mask. The currently defined bits,
  1648. when turned on, have the following meaning:
  1649.  
  1650.         Bit 0:   Successful completion.
  1651.         Bit 1:   Protocol requires no communications program supplied file
  1652.                  requester for receive: either the XPR supplies the file
  1653.                  requester or the protocol is capable of receiving file name
  1654.                  information through other means (e.g., from the host).
  1655.         Bit 2:   Protocol requires no communications program supplied file
  1656.                  requester for send: either the XPR supplies the file requester
  1657.                  or the protocol is capable of receiving file name information
  1658.                  through other means.
  1659.         Bit 3:   Communications program is requested to call XProtocolHostMon()
  1660.                  for all serial port input (see section 6.3).
  1661.         Bit 4:   Communications program is requested to call XProtocolUserMon()
  1662.                  for all user input (see section 6.3).
  1663.         Bit 5:   Communications program is requested to call XProtocolHostMon()
  1664.                  without waiting for serial input (see section 6.3).
  1665.  
  1666.         The value 0L is returned to indicate failure.
  1667.  
  1668.  
  1669. 6.1.2 XProtocolSend()
  1670. ---------------------
  1671.  
  1672. The calling sequence is:
  1673.  
  1674.         long status = XProtocolSend(struct XPR_IO *IO);
  1675.         D0                          A0
  1676.  
  1677. where struct XPR_IO is defined as in section 3 and appendix B.
  1678.         The value 0L is returned to indicate failure, 1L to indicate success.
  1679. Other non-zero return codes are also to be interpreted as successful, but the
  1680. meaning of the other bits is not currently specified.
  1681.  
  1682.  
  1683. 6.1.3 XProtocolReceive()
  1684. ------------------------
  1685.  
  1686. The calling sequence is:
  1687.  
  1688.         long status = XProtocolReceive(struct XPR_IO *IO);
  1689.         D0                             A0
  1690.  
  1691. where struct XPR_IO is defined as in section 3 and appendix B.
  1692.         The value 0L is returned to indicate failure, 1L to indicate success.
  1693. Other non-zero return codes are also to be interpreted as successful, but the
  1694. meaning of the other bits is not currently specified.
  1695.  
  1696.  
  1697. 6.1.4 XProtocolCleanup()
  1698. ------------------------
  1699.  
  1700. The calling sequence is:
  1701.  
  1702.         long status = XProtocolCleanup(struct XPR_IO *IO);
  1703.         D0                             A0
  1704.  
  1705. where struct XPR_IO is defined as in section 3 and appendix B.
  1706.         The value 0L is returned to indicate failure, 1L to indicate success.
  1707. Other non-zero return codes are also to be interpreted as successful, but the
  1708. meaning of the other bits is not currently specified.
  1709.  
  1710.  
  1711.  
  1712.  
  1713. 6.2 XPR_IO extension functions.
  1714. -------------------------------
  1715.  
  1716.         The following functions are now part of the XPR_IO extended structure
  1717. definition:
  1718.  
  1719.         xpr_options()     Prompts user for commands or options.
  1720.         xpr_unlink()      Deletes files by name.
  1721.         xpr_squery()      Returns actual size of current serial buffer contents.
  1722.         xpr_getptr()      Gets various pointers from user.
  1723.  
  1724.         The following sections will discuss each of these functions in detail.
  1725.  
  1726.  
  1727. 6.2.1    long  *xpr_options();
  1728. ------------------------------
  1729.  
  1730.         This function is in the first extension field of the XPR_IO structure.
  1731. Only use this function if the value of the xpr_extension field is 1L or larger.
  1732. The calling sequence is:
  1733.  
  1734.         long status = (*xpr_options)(long n, struct xpr_option *opt[])
  1735.         D0                           D0      A0
  1736.  
  1737. The function passes to the comm program a pointer to an array of n pointers to
  1738. xpr_option structures, where n is limited to 31. The xpr_option structures are
  1739. defined as follows:
  1740.  
  1741. struct xpr_option {
  1742.    char *xpro_description;      /* description of the option                  */
  1743.    long  xpro_type;             /* type of option                             */
  1744.    char *xpro_value;            /* pointer to a buffer with the current value */
  1745.    long  xpro_length;           /* buffer size                                */
  1746. }
  1747.  
  1748. Valid values for xpro_type are:
  1749.  
  1750. #define XPRO_BOOLEAN 1L         /* xpro_value is "yes", "no", "on" or "off"   */
  1751. #define XPRO_LONG    2L         /* xpro_value is string representing a number */
  1752. #define XPRO_STRING  3L         /* xpro_value is a string                     */
  1753. #define XPRO_HEADER  4L         /* xpro_value is ignored                      */
  1754. #define XPRO_COMMAND 5L         /* xpro_value is ignored                      */
  1755. #define XPRO_COMMPAR 6L         /* xpro_value contains command parameters     */
  1756.  
  1757.         The array is allocated and initialized by the XPR to default values. If
  1758. the comm program implements this function, it should display the description of
  1759. the option and its current value to the user and allow him/her to change them.
  1760. This could be accomplished either by dynamically building a requester or by
  1761. displaying each line one at a time and allow the user to enter new values or
  1762. accept the default. Options that have boolean values could be implemented by the
  1763. comm program as boolean gadgets, but the new value must be returned as "yes" or
  1764. "on" for logical 1 or "no" or "off" for logical 0 in the xpro_value buffer.
  1765. Note, that the XPR, if it uses this function must recognize both "yes" and "on"
  1766. for logical 1 and "no" and "off" for logical 0. Long values must if necessary be
  1767. converted to a string and copied to the xpro_value buffer.  For options that
  1768. have string values, the comm program must ensure that the new string selected by
  1769. the user fits in the value buffer as determined by the xpro_length field. The
  1770. buffer is supplied by the XPR, and must be large enough to be able to hold the
  1771. '\0' termination.
  1772.         The option of type XPRO_HEADER contains a pointer to an explanatory
  1773. message in its xpro_description field. It is to be interpreted as a header
  1774. string for the options that follow. It has no other function, any bits
  1775. corresponding to this option in the return value should be ignored, and the
  1776. xpr_value string is meaningless, but should be initialized to either NULL or a
  1777. valid pointer to a buffer. The message should have a length of 50 characters or
  1778. less.
  1779.         The options of type XPRO_COMMAND and XPRO_COMMPAR are used for such
  1780. functions as Kermit Bye or Finish. Simple commands (XPRO_COMMAND) could be
  1781. displayed as boolean gadgets in a requester, while commands needing parameters
  1782. could have an associated string gadget. The difference between commands like
  1783. this and other options is that when one of these commands is selected, the
  1784. requester should disappear and xpr_options() should return immediately, with
  1785. only the bit coresponding to the command set. Therefore, ideally, the XPR should
  1786. not mix XPRO_COMMAND/XPRO_COMMPAR options with other options (except of type
  1787. XPRO_HEADER). Rather, the XPR should first call xpr_options() with only 
  1788. XPRO_COMMAND/XPRO_COMMPAR/XPRO_HEADER options, one of which would be a "Change
  1789. Defaults" command (type XPRO_COMMAND). This command, when selected, would cause
  1790. the XPR to call xpr_options() with a list of other xpr_option structures for
  1791. non-commands and their headers. This way, the communications program would
  1792. automatically list the XPR commands first, and one of the commands would be a
  1793. "Change Defaults" command, which when selected by the user would bring up a
  1794. second requester with the various other options supported by the XPR. For simple
  1795. commands, the xpr_value string is meaningless and should either be set to NULL
  1796. or contain a valid pointer to a buffer anyway. For commands needing parameters,
  1797. the xpr_value string should contain the current default value of the parameter.
  1798. There is a compatibility issue: communications programs written with earlier
  1799. versions of the XPR spec may not know about XPRO_COMMAND etc. It is therefore
  1800. advisable to bring up the second requester anyway if no command is selected
  1801. from the first requester. In that case, it would be a good idea to include a
  1802. "CANCEL" command in the first requester, which does nothing but provide a means
  1803. to prevent the second requester from appearing.
  1804.  
  1805.         As an example, when selecting a ZMODEM based XPR the following array of
  1806. xpr_option structures could be passed to the comm program:
  1807.  
  1808. xpro_description                xpro_value    xpro_type
  1809. --------------------------------------------------------------
  1810. Convert NL to NL/CR             no            XPRO_BOOLEAN
  1811. Escape only CTRL chars          yes           XPRO_BOOLEAN
  1812. Escape ALL chars                no            XPRO_BOOLEAN
  1813. Send full pathname              yes           XPRO_BOOLEAN
  1814. Send 1K blocks                  no            XPRO_BOOLEAN
  1815. Subpacket length                512           XPRO_LONG
  1816. Disable 32-bit CRC              no            XPRO_BOOLEAN
  1817. Protect destination file        no            XPRO_BOOLEAN
  1818. Timeout value (sec)             10            XPRO_LONG
  1819. Delete after transmission       no            XPRO_BOOLEAN
  1820. Overwrite existing file         no            XPRO_BOOLEAN
  1821.  
  1822. Notice again, that the COMM program still knows little about the individual
  1823. option items (and in fact there is no way for it to find out, in keeping with
  1824. the philosophy of XPR). Also notice that a cheap way to implement this function
  1825. is to loop over the n supplied xpr_option's and to call the likely already
  1826. implemented xpr_gets function with the option description and the value buffer
  1827. (but remember that some options may not have valid value buffers!).
  1828.         It is important to follow a few rules when calling this function: the
  1829. description strings should be 25 characters or less (except for XPRO_HEADER's).
  1830. The value strings can be any length up to 255 characters, but be aware that in a
  1831. typical situation only about 10 to 15 of them will be displayed in a string
  1832. gadget.
  1833.         The return value, status, reflects which options have changed by having
  1834. the corresponding bit set. The first option in the xpr_option array corresponds
  1835. to  bit 0 (low-order), etc. If the options are all of the types boolean, long,
  1836. string or header, the comm program may decide to not detect whether the options
  1837. changed or not, and 0x07FFFFFFL may be returned, in effect specifying that all
  1838. options have changed. On the other hand, if the communications program returns
  1839. a value with multiple bits set even though some or all of the options are of
  1840. type command, the XPR should be careful to cause minimal damage, or display
  1841. an error message.
  1842.         If nothing changed or no command was selected, 0L is returned. If an
  1843. error occurred, the function returns -1L.
  1844.  
  1845.  
  1846. 6.2.2    long  *xpr_unlink();
  1847. -----------------------------
  1848.  
  1849.         This function is in the second extension field of the XPR_IO structure.
  1850. Only use this function if the value of the xpr_extension field is 2L or larger.
  1851. The calling sequence is:
  1852.  
  1853.         long status = (*xpr_unlink)(char *filename)
  1854.         D0                          A0
  1855.  
  1856. This function returns 0L on success, -1L on failure. It attempts to delete the
  1857. file who's name is contained in the character array pointed to bye the only
  1858. argument. The file cannot be locked at the time by any process.
  1859.  
  1860.  
  1861. 6.2.3    long  *xpr_squery();
  1862. ------------------------------
  1863.  
  1864.         This function is in the third extension field of the XPR_IO structure.
  1865. Only use this function if the value of the xpr_extension field is 3L or larger.
  1866. The calling sequence is:
  1867.  
  1868.         long size = (*xpr_squery)()
  1869.         D0
  1870.  
  1871.         This function returns the number of characters currently available
  1872. in the serial device. It returns -1L on error. When no characters are available
  1873. the function returns 0L.
  1874.  
  1875.  
  1876. 6.2.4    long  *xpr_getptr();
  1877. -----------------------------
  1878.  
  1879.         This function is in the fourth extension field of the XPR_IO structure.
  1880. Only use this function if the value of the xpr_extension field is 4L or larger.
  1881. The calling sequence is:
  1882.  
  1883.         long *ptr = (*xpr_getptr)(type)
  1884.         D0                        D0
  1885.  
  1886. This function returns selected pointers to structures or buffers defined in 
  1887. the communications program.
  1888.         Currently the only allowed pointer type is 
  1889.  
  1890.         type:                   resulting pointer:         
  1891.         ...................................................
  1892.  
  1893.         1L                      pointer to custom Screen
  1894.                                 or 0L for Workbench.
  1895.  
  1896.         (other values)          (to be determined)
  1897.  
  1898. This function can be used to open windows on the communications program's
  1899. custom screen, and together with the library functions XProtocolHostMon() and
  1900. XProtocolUserMon() such protocols as DoubleTalk should be feasible. Indeed,
  1901. entire external terminal emulations might be written in this way.
  1902.  
  1903. The function returns -1L on failure. Note that the failure can be due to 
  1904. various causes: the communications program may not want to return a particular
  1905. pointer, the version may not know about some allowed types, or the type may for
  1906. other reasons not be valid. Also: if 0L is returned, it is up to the XPR to 
  1907. determine whether this is a legal return value. With type 1, this is fine, but
  1908. in general a NULL pointer may of course not be valid. The XPR is responsible
  1909. for closing any windows or other resources on a call to XProtocolCleanup().
  1910.  
  1911.  
  1912. 6.3 New library functions.
  1913. --------------------------
  1914.  
  1915.         We now discuss the two library functions XProtocolHostMon and
  1916. XProtocolUserMon(). These two functions are provided by the XPR as additional
  1917. library entries and their presence is made known to the communications program
  1918. by setting certain bits in the return value of XProtocolSetup(). They are called
  1919. by the communcations program whenever data is received from (HostMon) or sent to
  1920. (UserMon) the serial port, except that care has to be taken that these functions
  1921. are not called directly or indirectly by the xpr_sread() and xpr_swrite()
  1922. functions.
  1923.  
  1924.  
  1925. 6.3.1 XProtocolHostMon()
  1926. ------------------------
  1927.  
  1928.         This function should be called by the communications program only when
  1929. bit 3 of the flags returned by XProtocolSetup() is set. Calling this function
  1930. when bit 3 is not set will probably cause a system failure. The function should
  1931. be called just after any input from the serial device is received, and just
  1932. before anything else is done with the received data. The calling sequence is
  1933.  
  1934.         long newactual = XProtocolHostMon(struct XPR_IO *IO, char *serbuff,
  1935.         D0                                A0                 A1
  1936.                                           long actual, long maxsize)
  1937.                                           D0           D1
  1938.  
  1939. Here, IO is a previously initialized XPR_IO structure, serbuff is a pointer to a
  1940. buffer containing the data from the serial device, actual is the number of bytes
  1941. received from the serial device, and maxsize is the actual allocated size of
  1942. serbuff. The XPR is entitled to make any modifications to the data in serbuff it
  1943. wants, as long as the amount of modified data does not overflow the buffer as
  1944. indicated by maxsize. When the XPR is done looking at or changing the data, it
  1945. returns the new actual number of bytes of data in serbuff in newactual. Note,
  1946. that some actions of the XPR may cause the buffer to become invalid: for
  1947. efficiency, the communications program will usually hand a pointer to its one
  1948. and only serial port read buffer in "serbuff" rather than making a copy every
  1949. time. Whenever the XPR, based on the information found in the buffer, decides to
  1950. call any of the callbacks that deal with the serial device (xpr_sread(),
  1951. xpr_sflush(), xpr_squery()), the communications program may reuse the buffer,
  1952. erasing the previous contents. Consequently, if the XPR needs to preserve the
  1953. contents of the buffer, it must first make a local copy. Whenever there is a
  1954. chance that the data in serbuff was invalidated, the XPR should return
  1955. newactual = 0L.
  1956.     Note to the communications program author: when this function is called
  1957. after serial input was received, the state of the communications program is
  1958. usually such that no serial read request is outstanding. Still, the XPR may
  1959. start a file transfer from inside XProtocolHostMon. This situation is different
  1960. from the case where the user requests an upload or download by selecting e.g. a
  1961. menu item: at such a time, the communications program typically does have an
  1962. outstanding serial read request. Moreover, upon return from the
  1963. XProtocolHostMon() call, a previous call by the XPR to xpr_sread() may have
  1964. caused a serial read request to be queued. It is therefore important that the
  1965. communications program ensure that read requests are queued when appropriate,
  1966. including from inside xpr_sread(), and that read requests are not queued more
  1967. than once.
  1968.     Some XPR's may require control even when there is no outstanding
  1969. serial input or user input. In order to prevent the communications program
  1970. from going into a Wait() state, there is another bit returned by
  1971. XProtocolSetup(). When bit 5 is set, the communications program should not
  1972. wait, but call XProtocolHostMon() instead. If XProtocolHostMon() returns a
  1973. non-zero newactual, the data in serbuff should be treated just as if new
  1974. serial input was received. The XPR should never set this bit unless there is
  1975. a good reason: bypassing the communications program's Wait is very multitasking
  1976. unfriendly.
  1977.  
  1978.         This function, together with XProtocolUserMon(), can be used to modify
  1979. the behavior of communications programs dramatically. Especially, the entire data
  1980. handling of the communications program could be bypassed by returning newactual
  1981. = 0L, and processing all data inside of XProtocolHostMon(), effectively allowing
  1982. external terminal emulations if the XPR were to open appropriate windows for
  1983. displaying the data. It is in fact possible to have both an external protocol
  1984. (XPR) and an external emulation (XEM) running at the same time: the best way
  1985. to do this is to have duplicate copies of the xpr.lib glue routines, one for
  1986. XPR's and one for XEM's. It is recommended that names of external emulation
  1987. libraries follow the prescription: xem<emulation>.library, e.g. xemvt100.library
  1988. or xemtek4014.library.
  1989.         Another use for these functions would be to decode and encode and
  1990. perhaps compress the data after, resp. before transmission, for example for use
  1991. with hosts supporting error correction/detection protocols such as MNP.
  1992.         A more mundane purpose of this function is to watch the data stream
  1993. for incoming escape or control sequences otherwise not supported by the 
  1994. communications program. Most notably, those sequences used to automatically
  1995. start file transfers as in ZMODEM or CompuServe B+, etc. When such a sequence
  1996. is detected, the XPR should directly call the appropriate XPR function to
  1997. handle the transfer from inside XProtocolHostMon(), and return newactual = 0L
  1998. to the communications program after the transfer has finished.
  1999.     Note to the XPR implementer: if the protocol the XPR implements is able
  2000. to autostart using XProtocolHostMon(), but als needs user input, it can use
  2001. xpr_gets() or xpr_options(). If those functions do not satisfy the need, the XPR
  2002. must use other means. One should be aware that for example the ARP file
  2003. requester can be called from inside an XPR library, in the same manner as it
  2004. can be called from any other program. The function xpr_getptr() can be used to
  2005. retrieve the pointer to the communications program's screen.
  2006.  
  2007.  
  2008. 6.3.2 XProtocolUserMon()
  2009. ------------------------
  2010.  
  2011.         This function should be called by the communications program only when
  2012. bit 4 of the flags returned by XProtocolSetup() is set. Calling this function
  2013. when bit 4 is not set will probably cause a system failure. The function should
  2014. be called just before any output is sent to the serial device. The calling
  2015. sequence is
  2016.  
  2017.         long newactual = XProtocolUserMon(struct XPR_IO *IO, char *serbuff,
  2018.         D0                                A0                 A1
  2019.                                           long actual, long maxsize)
  2020.                                           D0           D1
  2021.  
  2022. Here, IO is a previously initialized XPR_IO structure, serbuff is a pointer to a
  2023. buffer containing the data to be sent to the host, actual is the number of bytes
  2024. to be sent, and maxsize is the actual allocated size of serbuff. The XPR is
  2025. entitled to make any modifications to the data in serbuff it wants, as long as
  2026. the amount of modified data does not overflow the buffer as indicated by
  2027. maxsize. When the XPR is done looking at or changing the data, it returns the
  2028. new actual number of bytes of data in serbuff in newactual.
  2029.         This function, together with XProtocolHostMon(), can be used to modify
  2030. the behavior of communications programs dramatically. Especially, the entire data
  2031. handling of the communications program could be bypassed by returning newactual
  2032. = 0L, and processing all data inside of XProtocolUserMon(), effectively allowing
  2033. external terminal emulations, if the XPR were to open appropriate windows for
  2034. displaying the data. To get RAW KEY user input etc., the XPR would however have
  2035. to also open its own windows for IDCMP input. To that end, the function
  2036. xpr_getptr can be used to obtain the pointer to the screen of the communications
  2037. program where the window(s) should open.
  2038.         Another use for these functions would be to decode and encode and
  2039. perhaps compress the data after, resp. before transmission, for example for use
  2040. with hosts supporting error correction/detection protocols such as MNP.
  2041.  
  2042.                               __                
  2043.                              /  \ o    /        
  2044.                        -----/----\----/-----
  2045.                            /    o \__/          
  2046.                                                 
  2047.  
  2048. This concludes the documentation on external protocols using Amiga shared
  2049. libraries. If you have any questions, comments or suggestions, contact me on
  2050. BIX.
  2051.         Meanwhile, have fun!
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059.  
  2060. Appendix A: XPR library skeleton.
  2061. =================================
  2062.  
  2063. ;;; libface.c
  2064. ;
  2065. ;   DESCRIPTION:
  2066. ;   ===========
  2067. ;
  2068. ;       This is the skeleton for an Amiga Exec library.
  2069. ;       This version is written for Aztec C. It is based on the example
  2070. ;       library by Jim Mackraz who got some stuff from Neil Katin.
  2071. ;       This library implements a protocol transfer library.
  2072. ;       All changes and additions by me.
  2073. ;
  2074. ;   AUTHOR/DATE:  W.G.J. Langeveld, February 1989.
  2075. ;   ============
  2076. ;
  2077. ;;;
  2078.  
  2079.         include 'exec/types.i'
  2080.  
  2081. setup   macro
  2082.         movem.l d2/d3/d4-d7/a2-a6,-(sp)
  2083.         jsr     _geta4                  ;set up a4 for small model
  2084.         endm
  2085.  
  2086. push    macro
  2087.         move.l  \1,-(sp)
  2088.         endm
  2089.  
  2090. fix     macro
  2091.         ifc     '\1',''
  2092.                 mexit
  2093.         endc
  2094.         ifle    \1-8
  2095.                 addq.l  #\1,sp
  2096.         endc
  2097.         ifgt    \1-8
  2098.                 lea     \1(sp),sp
  2099.         endc
  2100.         endm
  2101.  
  2102. restore macro
  2103.         fix     \1
  2104.         movem.l (sp)+,d2/d3/d4-d7/a2-a6 
  2105.         rts
  2106.         endm
  2107.  
  2108.         dseg
  2109.  
  2110.         public  _libfunctab
  2111. _libfunctab:
  2112.         dc.l    XPRopen
  2113.         dc.l    XPRclose
  2114.         dc.l    XPRexpunge
  2115.         dc.l    $0000
  2116.         dc.l    XPRXProtocolCleanup
  2117.         dc.l    XPRXProtocolSetup
  2118.         dc.l    XPRXProtocolSend
  2119.         dc.l    XPRXProtocolReceive
  2120.         dc.l    XPRXProtocolHostMon
  2121.         dc.l    XPRXProtocolUserMon
  2122.         dc.l    $ffffffff
  2123.  
  2124.         cseg
  2125.  
  2126.         ;--- library functions
  2127.         public  _XPROpen
  2128.         public  _XPRClose
  2129.         public  _XPRExpunge
  2130.         public  _XProtocolCleanup
  2131.         public  _XProtocolSetup
  2132.         public  _XProtocolSend
  2133.         public  _XProtocolReceive
  2134.         public  _XProtocolHostMon
  2135.         public  _XProtocolUserMon
  2136.  
  2137.         public  _geta4
  2138.  
  2139. XPRopen:
  2140.         setup
  2141.         push a6
  2142.         jsr     _XPROpen
  2143.         restore 4
  2144.  
  2145. XPRclose:
  2146.         setup
  2147.         push a6
  2148.         jsr     _XPRClose
  2149.         restore 4
  2150.  
  2151. XPRexpunge:
  2152.         setup
  2153.         push a6
  2154.         jsr     _XPRExpunge
  2155.         restore 4
  2156.  
  2157. XPRXProtocolCleanup:
  2158.         setup
  2159.         push a0
  2160.         jsr     _XProtocolCleanup
  2161.         restore 4
  2162.  
  2163. XPRXProtocolSetup:
  2164.         setup
  2165.         push a0
  2166.         jsr     _XProtocolSetup
  2167.         restore 4
  2168.  
  2169. XPRXProtocolSend:
  2170.         setup
  2171.         push a0
  2172.         jsr     _XProtocolSend
  2173.         restore 4
  2174.  
  2175. XPRXProtocolReceive:
  2176.         setup
  2177.         push a0
  2178.         jsr     _XProtocolReceive
  2179.         restore 4
  2180.  
  2181. XPRXProtocolHostMon:
  2182.         setup
  2183.         push d1
  2184.         push d0
  2185.         push a1
  2186.         push a0
  2187.         jsr     _XProtocolHostMon
  2188.         restore 16
  2189.  
  2190. XPRXProtocolUserMon:
  2191.         setup
  2192.         push d1
  2193.         push d0
  2194.         push a1
  2195.         push a0
  2196.         jsr     _XProtocolUserMon
  2197.         restore 16
  2198.  
  2199.  
  2200.         end
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206. Appendix B: The xproto.h include file
  2207. =====================================
  2208.  
  2209. /** xproto.h
  2210. *
  2211. *   Include file for External Protocol Handling
  2212. *
  2213. **/
  2214. /*
  2215. *   The structure
  2216. */
  2217. struct XPR_IO {
  2218.                   char  *xpr_filename;      /* File name(s)             */
  2219.                   long (*xpr_fopen)();      /* Open file                */
  2220.                   long (*xpr_fclose)();     /* Close file               */
  2221.                   long (*xpr_fread)();      /* Get char from file       */
  2222.                   long (*xpr_fwrite)();     /* Put string to file       */
  2223.                   long (*xpr_sread)();      /* Get char from serial     */
  2224.                   long (*xpr_swrite)();     /* Put string to serial     */
  2225.                   long (*xpr_sflush)();     /* Flush serial input buffer*/
  2226.                   long (*xpr_update)();     /* Print stuff              */
  2227.                   long (*xpr_chkabort)();   /* Check for abort          */
  2228.                   long (*xpr_chkmisc)();    /* Check misc. stuff        */
  2229.                   long (*xpr_gets)();       /* Get string interactively */
  2230.                   long (*xpr_setserial)();  /* Set and Get serial info  */
  2231.                   long (*xpr_ffirst)();     /* Find first file name     */
  2232.                   long (*xpr_fnext)();      /* Find next file name      */
  2233.                   long (*xpr_finfo)();      /* Return file info         */
  2234.                   long (*xpr_fseek)();      /* Seek in a file           */
  2235.                   long   xpr_extension;     /* Number of extensions     */
  2236.                   long  *xpr_data;          /* Initialized by Setup.    */
  2237.                   long (*xpr_options)();    /* Multiple XPR options.    */
  2238.                   long (*xpr_unlink)();     /* Delete a file.           */
  2239.                   long (*xpr_squery)();     /* Query serial device      */
  2240.                   long (*xpr_getptr)();     /* Get various host ptrs    */
  2241.               };
  2242. /*
  2243. *   Number of defined extensions
  2244. */
  2245. #define XPR_EXTENSION 4L
  2246.  
  2247. /*
  2248. *   The functions
  2249. */
  2250. extern long XProtocolSend(),  XProtocolReceive(),
  2251.             XProtocolSetup(), XProtocolCleanup();
  2252. /*
  2253. *   Flags returned by XProtocolSetup()
  2254. */
  2255. #define XPRS_FAILURE    0x00000000L
  2256. #define XPRS_SUCCESS    0x00000001L
  2257. #define XPRS_NORECREQ   0x00000002L
  2258. #define XPRS_NOSNDREQ   0x00000004L
  2259. #define XPRS_HOSTMON    0x00000008L
  2260. #define XPRS_USERMON    0x00000010L
  2261. #define XPRS_HOSTNOWAIT 0x00000020L
  2262. /*
  2263. *   The update structure
  2264. */
  2265. struct XPR_UPDATE {     long  xpru_updatemask;
  2266.                         char *xpru_protocol;
  2267.                         char *xpru_filename;
  2268.                         long  xpru_filesize;
  2269.                         char *xpru_msg;
  2270.                         char *xpru_errormsg;
  2271.                         long  xpru_blocks;
  2272.                         long  xpru_blocksize;
  2273.                         long  xpru_bytes;
  2274.                         long  xpru_errors;
  2275.                         long  xpru_timeouts;
  2276.                         long  xpru_packettype;
  2277.                         long  xpru_packetdelay;
  2278.                         long  xpru_chardelay;
  2279.                         char *xpru_blockcheck;
  2280.                         char *xpru_expecttime;
  2281.                         char *xpru_elapsedtime;
  2282.                         long  xpru_datarate;
  2283.                         long  xpru_reserved1;
  2284.                         long  xpru_reserved2;
  2285.                         long  xpru_reserved3;
  2286.                         long  xpru_reserved4;
  2287.                         long  xpru_reserved5;
  2288.                    };
  2289. /*
  2290. *   The possible bit values for the xpru_updatemask are:
  2291. */
  2292. #define XPRU_PROTOCOL           0x00000001L
  2293. #define XPRU_FILENAME           0x00000002L
  2294. #define XPRU_FILESIZE           0x00000004L
  2295. #define XPRU_MSG                0x00000008L
  2296. #define XPRU_ERRORMSG           0x00000010L
  2297. #define XPRU_BLOCKS             0x00000020L
  2298. #define XPRU_BLOCKSIZE          0x00000040L
  2299. #define XPRU_BYTES              0x00000080L
  2300. #define XPRU_ERRORS             0x00000100L
  2301. #define XPRU_TIMEOUTS           0x00000200L
  2302. #define XPRU_PACKETTYPE         0x00000400L
  2303. #define XPRU_PACKETDELAY        0x00000800L
  2304. #define XPRU_CHARDELAY          0x00001000L
  2305. #define XPRU_BLOCKCHECK         0x00002000L
  2306. #define XPRU_EXPECTTIME         0x00004000L
  2307. #define XPRU_ELAPSEDTIME        0x00008000L
  2308. #define XPRU_DATARATE           0x00010000L
  2309. /*
  2310. *   The xpro_option structure
  2311. */
  2312. struct xpr_option {
  2313.    char *xpro_description;      /* description of the option                  */
  2314.    long  xpro_type;             /* type of option                             */
  2315.    char *xpro_value;            /* pointer to a buffer with the current value */
  2316.    long  xpro_length;           /* buffer size                                */
  2317. };
  2318. /*
  2319. *   Valid values for xpro_type are:
  2320. */
  2321. #define XPRO_BOOLEAN 1L         /* xpro_value is "yes", "no", "on" or "off"   */
  2322. #define XPRO_LONG    2L         /* xpro_value is string representing a number */
  2323. #define XPRO_STRING  3L         /* xpro_value is a string                     */
  2324. #define XPRO_HEADER  4L         /* xpro_value is ignored                      */
  2325. #define XPRO_COMMAND 5L         /* xpro_value is ignored                      */
  2326. #define XPRO_COMMPAR 6L         /* xpro_value contains command parameters     */
  2327.  
  2328.